package com.yazi.mxz.server.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonView;
import com.yazi.mxz.common.entity.beans.Ad;
import com.yazi.mxz.common.entity.enums.AdDevType;
import com.yazi.mxz.common.service.AdService;
import com.yazi.mxz.server.request.ListRequest;
import com.yazi.mxz.server.response.AdListResponse;
import com.yazi.mxz.server.response.view.BaseView;

@Controller("adController")
@RequestMapping("/ad")
public class AdController extends BaseController {
	private static Logger log = LoggerFactory.getLogger(Ad.class);
	
	@Resource
	AdService adService;
	
	@RequestMapping("/list")
	@ResponseBody
	@JsonView(BaseView.class)
	public AdListResponse list(@RequestBody ListRequest<Ad> req) {
		log.debug("客户端 -> 获取焦点广告列表");
		AdListResponse res = new AdListResponse();
		try{
			Ad ad = req.getQueryObject();
			ad.setStatus(true);
			ad.setDevType(AdDevType.TOUCH.ordinal()); // 触屏版
			
			List<Ad> adList = adService.search(ad, req.getPageInfo(), null);
			
			res.setSuccessData(adList);
			res.setOk();
		} catch (Exception e) {
			log.error("客户端 -> 获取焦点广告时异常", e);
			res.setErrorMessage(e.getMessage());
		}
		return res;
	}
}
